'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate', 'validate.en' ], function($) {
    return {
      init : function(data) {
        this.name = data.name;
        this.errorMessage = data.errorMessage
        this.initAutoLogin();
      },
      
      initAutoLogin: function() {
        var that = this;
        
        if(!that.errorMessage) {
          if(that.name) {
            $(".login-input-area").addClass("hide");
            $(".auto-login-area").removeClass("hide");
            $.ajax({
              type: "POST",
              url: window.__CTX__.root + "/auto-login"
            }).done(function(data) {
              console.log(data)
              data = typeof data === 'String' ? JSON.parse(data) : data;
              if(parseInt(data.code) == 0) {  
                $("[name=j_username]").val(data.data.name);
                $("[name=j_password]").val(data.data.password);
                $("form").submit();
              }
            }).fail(function() {
              
            })
          }
        }
        
      },
      
      doFormSubmit: function() {
        
      }
    }
})
